package com.google.code.shardbatis.converter;

import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.delete.Delete;

public class DeleteSqlConverter extends AbstractSqlConverter {
	
	@Override
	public String getOriginalTableName(Statement statement) {
		if (!(statement instanceof Delete)) {
			throw new IllegalArgumentException("The argument statement must is instance of Delete.");
		}

		Delete delete = (Delete) statement;

		return delete.getTable().getName();
	}
	
	@Override
	public Statement doConvert(Statement statement, String tableName) {
		if (!(statement instanceof Delete)) {
			throw new IllegalArgumentException("The argument statement must is instance of Delete.");
		}

		Delete delete = (Delete) statement;

		delete.getTable().setName(tableName);

		return delete;
	}

}